<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><!-- 控制浏览器文件模式为IE8 -->
<title>角色權限修改</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="js/artDialog/skins/default.css" rel="stylesheet" type="text/css" />
<link href="css/sele.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/artDialog/artDialog.js?skin=blue"></script>
<script src="js/artDialog/plugins/iframeTools.js"></script>
<script type="text/javascript" src="js/operamasks-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/elegant/om-all.css" />
<script type="text/javascript" src="js/jquery.ztree.core-3.1.js"></script>
<script type="text/javascript" src="js/jquery.ztree.excheck-3.1.js"></script>
<link rel="stylesheet" type="text/css" href="css/zTreeStyle2.css" />
<script src="${pageContext.request.contextPath}/js/common.js"></script>
<script> 
(function (config) {
    config['lock'] = true;
    config['fixed'] = true;
    config['okVal'] = 'Ok';
    config['cancelVal'] = 'Cancel';
})(art.dialog.defaults);
</script>
<script type="text/javascript">
var setting = {
		view: {
			selectedMulti: false
		},
		check: {
			enable: true
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onCheck: onCheck,
			onClick: openOptionPage
		}
};
var zNodes = ${treeData };
var clearFlag = false;
function onCheck(e, treeId, treeNode) {
	count();
	if (clearFlag) {
		clearCheckedOldNodes();
	}
}
function openOptionPage(e,treeId, treeNode){
	var flag=treeNode.checked;
	if(flag){
		var nodeCode=treeNode.id;	
		var roleId=$("#roleId").val();	
		var w = 600;
		var h = 400;
		var url = "${pageContext.request.contextPath}/adminRole.do?action=setOptionPage&nodeCode="+nodeCode
				+"&roleId="+roleId+"&time="+new Date().getTime();
		if (browser_type() == 'safari-or-chrome') {
			strFeatures = "height="
					+ h
					+ ",width="
					+ w
					+ ",top=0,left=100,toolbar=no,menubar=no,scrollbars=no, resizable=yes,location=no, status=no,z-look=no";
			returnValue = window.open(url, "newwindow", strFeatures);
		} else {
			strFeatures = "dialogWidth=" + w + "px;dialogHeight=" + h
					+ "px;;scrollbars=no;status=yes;";
			returnValue = window.showModalDialog(url, window, strFeatures);
		} 
		if (returnValue == "refresh") {
			location.reload();
		}
	}
}

function clearCheckedOldNodes() {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo");
	nodes = zTree.getChangeCheckedNodes();
	for (var i=0, l=nodes.length; i<l; i++) {
		nodes[i].checkedOld = nodes[i].checked;
	}
}
function count() {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo");
	checkCount = zTree.getCheckedNodes(true).length;
	$("#func").empty();
	var checkNodes = zTree.getCheckedNodes(true);
	for(var i=0;i<checkNodes.length;i++){
		$("#func").append("<input type='hidden' name='functionId' value='"+checkNodes[i].id+"'/>");
	}
}
function createTree() {
	$.fn.zTree.init($("#treeDemo"), setting, zNodes);
	count();
}

function submitForm() {
	document.forms[0].submit();
}
$(document).ready(function(){
	$("#panel").omPanel({
		iconCls : "apple",
		header : true,
		title : '系統功能項',
		collapsed : false,//元件創建後為收起狀態
		collapsible : false //渲染收起與展開按鈕
	});
	createTree();			
	$("#init").bind("change", createTree);
	$("#last").bind("change", createTree);
	$("#expandAllBtn").bind("click", {type: "expandAll"	}, expandNode);
	$("#collapseAllBtn").bind("click", {type: "collapseAll"	}, expandNode);
	$("#expandAllBtn").click();
});


function expandNode(e) {
	var zTree = $.fn.zTree.getZTreeObj("treeDemo"), type = e.data.type, nodes = zTree.getSelectedNodes();
	if (type.indexOf("All") < 0 && nodes.length == 0){
		alert("请先选择一个父节点");
		}
	if (type == "expandAll") {	
		zTree.expandAll(true);
	} else if (type == "collapseAll")
	{	zTree.expandAll(false);
	} else {
		var callbackFlag = $("#callbackTrigger").attr("checked");
		for ( var i = 0, l = nodes.length; i < l; i++) {
			zTree.setting.view.fontCss = {};
			if (type == "expand") {
				zTree.expandNode(nodes[i], true, null, null, callbackFlag);
			} else if (type == "collapse") {
				zTree.expandNode(nodes[i], false, null, null, callbackFlag);
			} else if (type == "toggle") {
				zTree.expandNode(nodes[i], null, null, null, callbackFlag);
			} else if (type == "expandSon") {
				zTree.expandNode(nodes[i], true, true, null, callbackFlag);
			} else if (type == "collapseSon") {
				zTree.expandNode(nodes[i], false, true, null, callbackFlag);
			}
		}
	}
}




</script>
</head>
<body>

	<div class="place">
	    <span>位置：</span>
	    <ul class="placeul">
	    <li>首页</li>
		<li>系统管理</li>
	    <li><a href="#" onclick="javascript:window.location.href='./adminRole.do?action=list'"> 角色權限管理</a></li>
		<li>權限修改</li>
	    </ul>
    </div>
    <div class="rightinfo">
		<form id="form1" action="./adminRole.do?action=edit" method="post">

			<ul class="seachform">
				<li>
					<label>角色名称：</label>
					<input id="roleName" type="text" disabled="disabled" name="roleName" size="10" value="${role.roleName }" style="width:150px;height:32px;" class="scinput" autocomplete="off"/>
					<input type="hidden" value="${role.roleId }" name="roleId" id="roleId"/>
				</li>
				<li>
					<label>角色代码：</label>
				    <input id="roleCode" disabled="disabled" type="text" name="code" size="10" value="${role.roleCode }" style="width:250px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
				<li>
					<label>角色描述：</label>
					<input id="roleDesc" type="text" disabled="disabled" name="description" size="10" value="${role.description }" style="width:265px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
			</ul>
			<div id="panel">
				<div id="main">
					<a id="expandAllBtn" href="#" ><font size="3px" color="#FFA042">[全部展開]</font></a>
		 			<a id="collapseAllBtn" href="#" ><font size="3px" color="#FFA042">[全部收縮]</font></a>	
					<ul id="treeDemo" class="ztree"></ul>
				</div>
			</div>
			<div id="func">
				
			</div>
          	<ul class="forminfo" style="margin-top:30px;">
			    <li>
					<label>&nbsp;</label>
					<input name="" type="button" id="save" onclick="submitForm();" class="btn" value="确定"/> 
					<input style="margin-left:100px;" onclick="javascript:document.location.href = './adminRole.do?action=list';" type="button" class="cancel" value="取消" />
				</li>
		    </ul>   
	    </form>
	</div>
</body>
<script type="text/javascript">
window.onload=function(){
	var isAddSuccess = '${isAddSuccess}';
	if(isAddSuccess=="success")
	{
		j.omMessageBox.alert({
	           content:'修改角色成功！',
	           onClose:function(v){
	        	   document.location.href = './adminRole.do?action=list';
	           }
	       });
	}else if(isAddSuccess=="error")
	{
		j.omMessageBox.alert({
	           content:'修改角色失败！',
	           onClose:function(v){}
	       });
	}
};
</script>
</html>